<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-CN"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="Content-Language" content="zh-CN"><link href="stylesheet.css" media="all" rel="stylesheet" type="text/css">
<title>返回集合的函数</title>
<script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?d286c55b63a3c54a1e43d10d4c203e75"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script>
</head><body class="SECT1">
<div>
<table summary="Header navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><th colspan="5" align="center" valign="bottom">PostgreSQL 8.2.3 中文文档</th></tr>
<tr><td width="10%" align="left" valign="top"><a href="functions-comparisons.html" accesskey="P">后退</a></td><td width="10%" align="left" valign="top"><a href="functions.html">快退</a></td><td width="60%" align="center" valign="bottom">章9. 函数和操作符</td><td width="10%" align="right" valign="top"><a href="functions.html">快进</a></td><td width="10%" align="right" valign="top"><a href="functions-info.html" accesskey="N">前进</a></td></tr>
</table>
<hr align="LEFT" width="100%"></div>
<div class="SECT1"><h1 class="SECT1"><a name="FUNCTIONS-SRF">9.18. 返回集合的函数</a></h1><a name="AEN14191"></a><a name="AEN14194"></a>
<p>本节描述那些可能返回多于一行的函数。目前这个类型的函数只有序列号生成函数，如<a href="functions-srf.html#FUNCTIONS-SRF-SERIES">表9-39</a>所述。</p>
<div class="TABLE"><a name="FUNCTIONS-SRF-SERIES"></a>
<p><b>表9-39. 序列号生成函数</b></p>
<table border="1" class="CALSTABLE"><col><col><col><col>
<thead>
<tr><th>函数</th><th>参数类型</th><th>返回类型</th><th>描述</th></tr>
</thead>
<tbody>
<tr><td><tt class="LITERAL"><code class="FUNCTION">generate_series</code>(<tt class="PARAMETER">start</tt>, <tt class="PARAMETER">stop</tt>)</tt></td><td><tt class="TYPE">int</tt> 或 <tt class="TYPE">bigint</tt></td><td><tt class="TYPE">setof int</tt> 或 <tt class="TYPE">setof bigint</tt> (与参数类型相同)</td><td>生成一个数值序列，从 <tt class="PARAMETER">start</tt> 到 <tt class="PARAMETER">stop</tt> ，步长为 1 。</td></tr>
<tr><td><tt class="LITERAL"><code class="FUNCTION">generate_series</code>(<tt class="PARAMETER">start</tt>, <tt class="PARAMETER">stop</tt>, <tt class="PARAMETER">step</tt>)</tt></td><td><tt class="TYPE">int</tt> 或 <tt class="TYPE">bigint</tt></td><td><tt class="TYPE">setof int</tt> 或 <tt class="TYPE">setof bigint</tt> (与参数类型相同)</td><td>生成一个数值序列，从 <tt class="PARAMETER">start</tt> 到 <tt class="PARAMETER">stop</tt> ，步长为 <tt class="PARAMETER">step</tt> 。</td></tr>
</tbody>
</table>
</div>
<p>如果 <tt class="PARAMETER">step</tt> 是正数且 <tt class="PARAMETER">start</tt> 大于 <tt class="PARAMETER">stop</tt> ，那么返回零行。相反，如果 <tt class="PARAMETER">step</tt> 是负数且 <tt class="PARAMETER">start</tt> 小于 <tt class="PARAMETER">stop</tt> ，那么也返回零行。如果输入是 <tt class="LITERAL">NULL</tt> ，同样产生零行。<tt class="PARAMETER">step</tt> 为零则是一个错误。下面是一些例子：</p>
<pre class="PROGRAMLISTING">select * from generate_series(2,4);
 generate_series
-----------------
               2
               3
               4
(3 rows)

select * from generate_series(5,1,-2);
 generate_series
-----------------
               5
               3
               1
(3 rows)

select * from generate_series(4,3);
 generate_series
-----------------
(0 rows)

select current_date + s.a as dates from generate_series(0,14,7) as s(a);
   dates
------------
 2004-02-05
 2004-02-12
 2004-02-19
(3 rows)</pre>
</div>
<div>
<hr align="LEFT" width="100%">
<table summary="Footer navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td width="33%" align="left" valign="top"><a href="functions-comparisons.html" accesskey="P">后退</a></td><td width="34%" align="center" valign="top"><a href="index.html" accesskey="H">首页</a></td><td width="33%" align="right" valign="top"><a href="functions-info.html" accesskey="N">前进</a></td></tr>
<tr><td width="33%" align="left" valign="top">行和数组比较</td><td width="34%" align="center" valign="top"><a href="functions.html" accesskey="U">上一级</a></td><td width="33%" align="right" valign="top">系统信息函数</td></tr>
</table>
</div>
</body></html>